#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/wait.h>

pid_t pid;

void handler(int sig)
{
    if (sig == SIGINT || sig == SIGTSTP)
        kill(-pid, sig);
    if (sig == SIGCHLD)
    {
        printf("SIGCHLD\n");
        pid = waitpid(-1, NULL, 0);
        printf("%d\n", pid);
        exit(0);
    }
}

int main(int argc, char *argv[])
{
    int status;

    signal(SIGINT, handler);
    signal(SIGTSTP, handler);
    signal(SIGCHLD, handler);

    if ((pid = fork()) == 0)
    {
        setpgid(0,0);
        signal(SIGINT, SIG_DFL);
        signal(SIGTSTP, SIG_DFL);
        while(1);
    }

    while(1);
    /*waitpid(-1, &status, WUNTRACED);
    if (WIFEXITED(status))
        printf("%d", WEXITSTATUS(status));
    if (WIFSIGNALED(status))
        psignal(WTERMSIG(status), "signal is ");
    if (WIFSTOPPED(status))
        psignal(WSTOPSIG(status), "signal is ");
    */

    return 0;
}
